/*                                                                                                                                                            
The code examples copyrighted by Nokia Corporation that are included to                                                                                       
this material are licensed to you under following MIT-style License:                                                                                          

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the          
"Software"), to deal in the Software without restriction, including    
without limitation the rights to use, copy, modify, merge, publish,    
distribute, sublicense, and/or sell copies of the Software, and to     
permit persons to whom the Software is furnished to do so, subject to  
the following conditions:                                              

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.                 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF             
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 
*/

#include <MApplication>
#include <MApplicationWindow>

#include <gallery/gallerymodel.h>
#include <gallery/gallerypage.h>
#include <gallery/gallerygridpage.h>
#include <gallery/galleryfullscreenpage.h>
#include <gallery/gallerycontentprovider.h>
#include <gallery/gallerylocalcontentprovider.h>

int main(int argc, char **argv)
{
    if(argc < 2) {
        qDebug("ERROR: You need to provide at least one image file as an argument!");
        return 1;
    }

    int i;
    MApplication application(argc, argv);
    MApplicationWindow window;
    window.show();

    // Create the model and the content provider for it
    GalleryLocalContentProvider *provider = new GalleryLocalContentProvider();
    GalleryModel *model = new GalleryModel();
    model->addContentProvider(provider);

    // Create a grid page and show it
    GalleryGridPage *gridPage = new GalleryGridPage(*model);
    gridPage->appear();

    // Create a fullscreen page
    GalleryFullScreenPage *fullScreenPage = new GalleryFullScreenPage(*model);

    // Connect the pages so that the image tapped on grid page gets shown in the fullscreen page
    QObject::connect(gridPage, SIGNAL(itemSelected(QUrl)), fullScreenPage, SLOT(moveToItem(QUrl)));
    QObject::connect(gridPage, SIGNAL(itemSelected(QUrl)), fullScreenPage, SLOT(appear()));

    // Add user-specified image URLs:
    QList<QUrl> urls;
    for(i=1; i<argc; ++i) {
        urls << QUrl(argv[i]);
    }
    provider->setUrls(urls);
   
    int error = application.exec();
    delete fullScreenPage;
    delete gridPage;
    model->removeContentProvider(provider);
    delete model;
    delete provider;
    return error;
}
